package com.lgcns.android.otmeal.rest;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lgcns.android.otmeal.R;

/**
 * @author Jiyun Kang
 */
public class MenusListAdapter extends BaseAdapter 
{
	private List<Menu> _menus;
	private final LayoutInflater _layoutInflater;

	public MenusListAdapter(Context context, List<Menu> menus) 
	{
		_menus = menus;
		_layoutInflater = LayoutInflater.from(context);
	}

	public int getCount() 
	{
		return _menus.size();
	}

	public Menu getItem(int position) 
	{
		return _menus.get(position);
	}

	public long getItemId(int position) 
	{
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent) 
	{
		Menu menu = getItem(position);
		
		View view = convertView;
		
		if (view == null)
		{
			view = _layoutInflater.inflate(R.layout.menus_list_item, parent, false);
		}

		TextView t = (TextView) view.findViewById(R.id.menu_name); 
		t.setText(menu.getFormattedName());
		
		return view;
	}
}
